#!/usr/bin/perl -w

use Crypt::Lite;
$logfile = "installlog.txt";


print "\n";
print "Welcome to the P-Date Installer!\n";
print "It will guide you through a few simple steps to get";
print "\nP-date setup!";
print "\n\n";
print "Please wait a few seconds, then the installer will start";
print "\n\n";

sleep 6;

open(LOG, ">>$logfile");
print LOG ("started install\n");
close (LOG);

print "\-------------------------------------------------\n";

# this will make the users datefile (and the variable we use later)
print "Choose a name for your datefile (do not include extension): ";
$datefile = <STDIN>;
chomp $datefile;
open(DATE, ">$datefile.df");
close (DATE);
print "\n";
print "datefile created....\n\n";
open(LOG, ">>$logfile");
print LOG ("created datefile\n");
close (LOG);

&addpass;

# we are gonna pause (for kicks and giggles), then make the users config file!
print "\nMaking your personal Pdate Config file \(please wait while it is made\)\n\n";

sleep 3;

open(CONFIG, ">>config");
print CONFIG ("\$file = \"$datefile.df\";\n");
print CONFIG ("chomp \$file;\n");
close (CONFIG);
open(LOG, ">>$logfile");
print LOG ("made the config\n");
close (LOG);

print "The install is done!\n";
print "Enjoy P-Date!\n\n";
open(LOG, ">>$logfile");
print LOG ("finished install\n");
close (LOG);


sub addpass {
#sweet idea, lets add pass protection
print "\n";
print "Do you want this password file to have password protection? (y/n): ";
$yesorno = <STDIN>;
chomp $yesorno;
if ($yesorno eq "y") {
	open(CONFIG, ">>config");
	print CONFIG ("\$passprot = 1;\n");
	close (CONFIG);
	open(LOG, ">>$logfile");
	print LOG ("user chose to add password");
	close (LOG);
	print "\nWhat would you like your password to be?: ";
		my $password = <STDIN>;
		chomp $password;
		#encrypt!
		$crypt = Crypt::Lite->new( debug => 0 );
		$encrypted = $crypt->encrypt($password, 'passcheck');
			open(CONFIG, ">>config");
			print CONFIG ("\$password = \"$encrypted\";\n");
			print CONFIG ("chomp \$password;");
			close (CONFIG);
	open(LOG, ">>$logfile");
	print LOG ("added password");
	close (LOG);
		    }

elsif ($yesorno eq "n") {
	open(CONFIG, ">>config");
	print CONFIG ("my \$passprot = 0;\n");
	close (CONFIG);
	open(LOG, ">>$logfile");
	print LOG ("user chose not to add password");
	close (LOG);
			};
};
